<template>
  <div>
    <el-row
      type="flex"
      align="middle"
    >
      <el-col :span="22">工单精品列表</el-col>
    </el-row>
    <el-divider content-position="center"></el-divider>
    <el-row>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="false"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
      >
        <template #allNum>
          <div class="tabelAomut">
            <div>
              精品总金额：<span>￥{{ projectSum }}</span>
            </div>
            <div>
              精品优惠金额：<span>￥{{ projectSum - totalAmount }}</span>
            </div>
            <div>
              精品折后总金额：<span>￥{{ totalAmount }}</span>
            </div>
          </div>
        </template>
      </data-table>
    </el-row>
  </div>
</template>

<script>
import baseMixin from '@/mixins/base'

export default {
  name: 'carInfo',
  components: {},
  props: ['workOrderId', 'workOrderType'], // workOrderType 工单类型 1快速单
  mixins: [
    baseMixin({
      // findData: synthesizeJpPage,
      dataName: ['content', 'totalRecords'],
      idName: 'id',
    }),
  ],
  computed: {
    totalAmount () {
      let sum = 0
      this.tableData.forEach((item) => {
        //计算
        sum += Number(item.shouldAmount)
      })
      return sum
    },
    projectSum () {
      let sum = 0
      this.tableData.forEach((item) => {
        //计算
        sum += Number(item.currentPrice * item.num)
      })

      return sum
    },
  },
  data () {
    return {
      tableColumnAttributes: [
        { name: '精品编号', value: 'orderNo', type: 'text' },
        { name: '精品名称', value: 'name', type: 'text' },
        { name: '一级类别', value: 'appLargeIdOneValue', type: 'text' },
        { name: '二级类别', value: 'appLargeIdTwoValue', type: 'text' },
        { name: '供应商', value: 'supplierName', type: 'text' },
        { name: '销售价', value: 'currentPrice', type: 'text' },
        { name: '数量', value: 'num', type: 'text' },
        { name: '折扣', value: 'discount', type: 'text' },
        { name: '折后总价', value: 'shouldAmount', type: 'text' },
        { name: '收费类型', value: 'tollType', type: 'text' },
        { name: '备注', value: 'workUserName', type: 'text' },
      ],
      rules: [],
      searchOptions:{},
    }
  },
  async created () {
    this.notQuery = false;
    this.searchOptions[`${this.$parent.getConfig.orderBoutiqueList.queryField}`] = this.workOrderId
    this.setTableData()
  },
  methods: {
     async setTableData () {
      if (!this.notQuery) {
        let fun = this.$parent.getConfig.orderBoutiqueList.query;
        if (fun) {
          let res = await fun(this.searchOptions, this.pageSize, this.currentPage);
          this.totalCount = parseInt(res.data['totalRecords'])
          this.tableData = res.data['content'];
        }
      }
    },
    changeType (item) {
      this.selectedTypeText = item.label
    },
  },
  mounted () { },
}
</script>

<style lang="scss" scoped>
</style>
